﻿var loginStatus = '';

function modelInit() {
	// $.cookie('TV_CST_userName', '王工头', {
	//     expires: 7
	// });
	if(modelIndex.isIndex) {
		var area_id = TV.GetParam('area_id') || 0;
		$.cookie('TV_CST_AREA', area_id, {
			path: '/'
		});
	}
	var indexList = new TV.CookieOpt().getOpt()
	console.log(modelIndex.disHeaderm, 'modelIndex.disHeader')
	var index = indexList && typeof indexList.index == 'number' ? indexList.index : undefined;
	if(!modelIndex.disUser) {

		TV.UserMess()
	}

	// 	loginStatus = TV.UserMess()

	// } else {
	// 	TV.UserMess();
	// }

	if(!modelIndex.disHeader) {

		//      TV.getHeader();
	}
	console.log(loginStatus);

	//  if (index>length-1) {
	//
	//  }else{
	right.toggleFocus(index);

	//  }

}

/*
 * 1.右侧区
 */

cmsIndex.modules[cmsIndex.moduleGuid(cmsIndex.addModule())] = {
	modName: 'right',
	modNum: cmsIndex.moduleGuid(),
	map: {
		left: 0
	}
};

var right = cmsIndex.modules[cmsIndex.moduleGuid()].module = (function() {
	var mod = {
			modName: "index",
			modNum: cmsIndex.moduleGuid()
		},
		index = modelIndex.index, //位置
		listName = modelIndex.listName, //模块名
		containerId = modelIndex.containerId; //包含模块的标签id

	//操作
	mod.toggleFocus = function(number) {
		var me = mod;
		if(number != undefined) {
			index = number;
		}
		// TV.IndexOpt(containerId, listName, index);
		var elem = $("#" + containerId).children("." + listName);
		var elemHeader = $(".login");
		elemHeader.removeClass("login-active");
		// console.log(index)
		for(var i = 0; i < elem.length; i++) {
			elem[i].className = listName;
		}
		if(index == -1) {
			elemHeader.addClass("login-active");
		} else if(elem.length) {
			lengths = $(".model").length;
			if(lengths - 1 < index) {

			} else {
				elem[index].className = elem[index].className + ' active';
			}

		}
		if (modelIndex.isimg) {
			funimg(index)
		}
		return me;
	};

	//index 位置调整
	mod.moveOp = function(directive) {
		var me = mod;
		index = direOpt(index, directive);
		mod.toggleFocus();
		return me;
	};
	mod.action = function(directive) {
		var me = mod;
		switch(directive) {
			case 'back':
				if(modelIndex.isVideo && mp) {
					mp.stop();
				}
				if(modelIndex.imgShow) {
					new TV.CookieOpt().clean();
					$('.releaseImg').css('display', 'none')
					modelIndex.imgShow = !modelIndex.imgShow
				} else if(modelIndex.isExit) {
					window.history.go(-1);
				} else if(modelIndex.isIndex) {
					if(TV.GetParam('area_id') && TV.GetParam('area_id') != '0') {
						Utility.ioctlWrite("EnReach", "ExitBrowser");
					} else {
						window.close();
						Utility.ioctlWrite("EnReach", "ExitBrowser");
						// TV.PromptMsg(2333)
					}
				} else {
					window.history.go(-1);

				}
				return false;
				break;
			case 'enter':
				if(modelIndex.isVideo && mp) {
					mp.stop();
				}
				if(isCache) {
					var cookieTv = new TV.CookieOpt({
						index: index
					})
					var indexList = cookieTv.setOpt();
				}
				if(index == -1) {
					window.location.href = 'login.html'

					if(loginStatus) {
						// window.location.href = 'personal.html'

					} else {
						window.location.href = 'login.html'

					}

				} else if(index >= 0) {

					direEnter(index, directive);

				}
				break;
		}
		return me;
	};
	mod.grabEvent = function(key) {
		var me = mod;
		var keyJson = TV.GetKey(key);
		if(keyJson.keyState && keyJson.keyState != 'enter' && keyJson.keyState != 'back') {
			me.moveOp(keyJson.keyState);
		} else {
			me.action(keyJson.keyState)
		}
		return keyJson.isBlock;

	};

	return mod;
})();

cmsIndex.run();